// Copyright (C) 2005-2008 Jae Stutzman (jaebird@gmail.com)
//
// This file is part of Podducer.
//
// Podducer is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Podducer is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Podducer.  If not, see <http://www.gnu.org/licenses/>.

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

namespace Podducer
{
	/// <summary>
	/// Summary description for FrmConfig.
	/// </summary>
	public class FrmConfig : System.Windows.Forms.Form
	{
		private string selectedEncoder;
		private double trackBarDivider = 1;

		private string qualityLameEncoding;
		private string qualityOggVorbisEncoding;
		private string qualitySpeexEncoding;

		private System.Windows.Forms.GroupBox groupBox1;
		private System.Windows.Forms.ComboBox cbxSampleRate;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.ComboBox cbxBitsPerSample;
		private System.Windows.Forms.Label label3;
		private System.Windows.Forms.ComboBox cbxNumOfChannels;
		private System.Windows.Forms.Label label4;
		private System.Windows.Forms.TextBox txtDirectoryPath;
		private System.Windows.Forms.Button btnDirectoryBrowse;
		private System.Windows.Forms.Button btnSave;
		private System.Windows.Forms.Button btnCancel;
		private System.Windows.Forms.RadioButton btnOggVorbis;
		private System.Windows.Forms.RadioButton btnSpeex;
		private System.Windows.Forms.RadioButton btnMp3;
		private System.Windows.Forms.TrackBar trackBarQuality;
		private System.Windows.Forms.TextBox txtQuality;
		private System.Windows.Forms.GroupBox grpQuality;
		private System.Windows.Forms.Label lblMinTrack;
		private System.Windows.Forms.Label lblMaxTrack;
		private BC.Controls.TimeSlider sliderTime;
		private System.Windows.Forms.Label label5;
		private System.Windows.Forms.GroupBox groupBox2;
		private System.Windows.Forms.RadioButton btnCustomEncoder;
		private System.Windows.Forms.TextBox txtCmdLineEncoder;
		private System.Windows.Forms.Label label6;
		private System.Windows.Forms.Label label7;
		private System.Windows.Forms.TextBox txtFilenameMask;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public FrmConfig()
		{
			// Required for Windows Form Designer support
			InitializeComponent();
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.groupBox1 = new System.Windows.Forms.GroupBox();
			this.txtFilenameMask = new System.Windows.Forms.TextBox();
			this.label7 = new System.Windows.Forms.Label();
			this.sliderTime = new BC.Controls.TimeSlider();
			this.label5 = new System.Windows.Forms.Label();
			this.btnDirectoryBrowse = new System.Windows.Forms.Button();
			this.txtDirectoryPath = new System.Windows.Forms.TextBox();
			this.label4 = new System.Windows.Forms.Label();
			this.cbxNumOfChannels = new System.Windows.Forms.ComboBox();
			this.label3 = new System.Windows.Forms.Label();
			this.cbxBitsPerSample = new System.Windows.Forms.ComboBox();
			this.label2 = new System.Windows.Forms.Label();
			this.label1 = new System.Windows.Forms.Label();
			this.cbxSampleRate = new System.Windows.Forms.ComboBox();
			this.btnSave = new System.Windows.Forms.Button();
			this.btnCancel = new System.Windows.Forms.Button();
			this.grpQuality = new System.Windows.Forms.GroupBox();
			this.lblMaxTrack = new System.Windows.Forms.Label();
			this.lblMinTrack = new System.Windows.Forms.Label();
			this.txtQuality = new System.Windows.Forms.TextBox();
			this.trackBarQuality = new System.Windows.Forms.TrackBar();
			this.btnOggVorbis = new System.Windows.Forms.RadioButton();
			this.btnSpeex = new System.Windows.Forms.RadioButton();
			this.btnMp3 = new System.Windows.Forms.RadioButton();
			this.groupBox2 = new System.Windows.Forms.GroupBox();
			this.label6 = new System.Windows.Forms.Label();
			this.txtCmdLineEncoder = new System.Windows.Forms.TextBox();
			this.btnCustomEncoder = new System.Windows.Forms.RadioButton();
			this.groupBox1.SuspendLayout();
			((System.ComponentModel.ISupportInitialize)(this.sliderTime)).BeginInit();
			this.grpQuality.SuspendLayout();
			((System.ComponentModel.ISupportInitialize)(this.trackBarQuality)).BeginInit();
			this.groupBox2.SuspendLayout();
			this.SuspendLayout();
			// 
			// groupBox1
			// 
			this.groupBox1.Controls.Add(this.txtFilenameMask);
			this.groupBox1.Controls.Add(this.label7);
			this.groupBox1.Controls.Add(this.sliderTime);
			this.groupBox1.Controls.Add(this.label5);
			this.groupBox1.Controls.Add(this.btnDirectoryBrowse);
			this.groupBox1.Controls.Add(this.txtDirectoryPath);
			this.groupBox1.Controls.Add(this.label4);
			this.groupBox1.Controls.Add(this.cbxNumOfChannels);
			this.groupBox1.Controls.Add(this.label3);
			this.groupBox1.Controls.Add(this.cbxBitsPerSample);
			this.groupBox1.Controls.Add(this.label2);
			this.groupBox1.Controls.Add(this.label1);
			this.groupBox1.Controls.Add(this.cbxSampleRate);
			this.groupBox1.Location = new System.Drawing.Point(8, 12);
			this.groupBox1.Name = "groupBox1";
			this.groupBox1.Size = new System.Drawing.Size(392, 156);
			this.groupBox1.TabIndex = 0;
			this.groupBox1.TabStop = false;
			this.groupBox1.Text = "General";
			// 
			// txtFilenameMask
			// 
			this.txtFilenameMask.Location = new System.Drawing.Point(120, 20);
			this.txtFilenameMask.Name = "txtFilenameMask";
			this.txtFilenameMask.Size = new System.Drawing.Size(228, 20);
			this.txtFilenameMask.TabIndex = 12;
			this.txtFilenameMask.Text = "";
			// 
			// label7
			// 
			this.label7.Location = new System.Drawing.Point(8, 20);
			this.label7.Name = "label7";
			this.label7.Size = new System.Drawing.Size(112, 20);
			this.label7.TabIndex = 11;
			this.label7.Text = "Filename mask:";
			this.label7.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
			// 
			// sliderTime
			// 
			this.sliderTime.AllowSlidingMaximum = false;
			this.sliderTime.CustomFormat = "MM/dd/yy HH:mm";
			this.sliderTime.Format = BC.Controls.DateFormatEnum.Custom;
			this.sliderTime.LargeChange = System.TimeSpan.Parse("1.00:00:00");
			this.sliderTime.Location = new System.Drawing.Point(108, 104);
			this.sliderTime.Maximum = new System.DateTime(2007, 4, 26, 23, 22, 31, 875);
			this.sliderTime.Minimum = new System.DateTime(2006, 5, 5, 21, 50, 14, 890);
			this.sliderTime.Name = "sliderTime";
			this.sliderTime.SegmentColor = System.Drawing.Color.FromArgb(((System.Byte)(127)), ((System.Byte)(255)), ((System.Byte)(0)), ((System.Byte)(0)));
			this.sliderTime.SegmentEnd = new System.DateTime(((long)(0)));
			this.sliderTime.SegmentStart = new System.DateTime(((long)(0)));
			this.sliderTime.ShowLabelsAsDuration = true;
			this.sliderTime.ShowMaximumLabel = false;
			this.sliderTime.ShowMinimumLabel = false;
			this.sliderTime.ShowSegment = true;
			this.sliderTime.ShowValueLabel = true;
			this.sliderTime.Size = new System.Drawing.Size(272, 45);
			this.sliderTime.SmallChange = System.TimeSpan.Parse("00:05:00");
			this.sliderTime.TabIndex = 9;
			this.sliderTime.TickFrequency = System.TimeSpan.Parse("00:05:00");
			this.sliderTime.Value = new System.DateTime(2006, 5, 5, 21, 50, 14, 889);
			// 
			// label5
			// 
			this.label5.Location = new System.Drawing.Point(8, 108);
			this.label5.Name = "label5";
			this.label5.Size = new System.Drawing.Size(112, 40);
			this.label5.TabIndex = 10;
			this.label5.Text = "Max Recording Time (hh:mm):";
			this.label5.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
			// 
			// btnDirectoryBrowse
			// 
			this.btnDirectoryBrowse.Location = new System.Drawing.Point(352, 48);
			this.btnDirectoryBrowse.Name = "btnDirectoryBrowse";
			this.btnDirectoryBrowse.Size = new System.Drawing.Size(24, 20);
			this.btnDirectoryBrowse.TabIndex = 8;
			this.btnDirectoryBrowse.Text = "...";
			this.btnDirectoryBrowse.Click += new System.EventHandler(this.btnDirectoryBrowse_Click);
			// 
			// txtDirectoryPath
			// 
			this.txtDirectoryPath.Location = new System.Drawing.Point(120, 48);
			this.txtDirectoryPath.Name = "txtDirectoryPath";
			this.txtDirectoryPath.Size = new System.Drawing.Size(228, 20);
			this.txtDirectoryPath.TabIndex = 7;
			this.txtDirectoryPath.Text = "";
			// 
			// label4
			// 
			this.label4.Location = new System.Drawing.Point(8, 48);
			this.label4.Name = "label4";
			this.label4.Size = new System.Drawing.Size(112, 20);
			this.label4.TabIndex = 6;
			this.label4.Text = "Destination directory:";
			this.label4.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
			// 
			// cbxNumOfChannels
			// 
			this.cbxNumOfChannels.Items.AddRange(new object[] {
																  "1",
																  "2"});
			this.cbxNumOfChannels.Location = new System.Drawing.Point(336, 76);
			this.cbxNumOfChannels.Name = "cbxNumOfChannels";
			this.cbxNumOfChannels.Size = new System.Drawing.Size(40, 21);
			this.cbxNumOfChannels.TabIndex = 5;
			// 
			// label3
			// 
			this.label3.Location = new System.Drawing.Point(268, 76);
			this.label3.Name = "label3";
			this.label3.Size = new System.Drawing.Size(64, 20);
			this.label3.TabIndex = 4;
			this.label3.Text = "Channels:";
			this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
			// 
			// cbxBitsPerSample
			// 
			this.cbxBitsPerSample.Items.AddRange(new object[] {
																  "8",
																  "16"});
			this.cbxBitsPerSample.Location = new System.Drawing.Point(220, 76);
			this.cbxBitsPerSample.Name = "cbxBitsPerSample";
			this.cbxBitsPerSample.Size = new System.Drawing.Size(40, 21);
			this.cbxBitsPerSample.TabIndex = 3;
			// 
			// label2
			// 
			this.label2.Location = new System.Drawing.Point(148, 76);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(68, 20);
			this.label2.TabIndex = 2;
			this.label2.Text = "Bits/sample:";
			this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
			// 
			// label1
			// 
			this.label1.Location = new System.Drawing.Point(8, 76);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(68, 20);
			this.label1.TabIndex = 1;
			this.label1.Text = "Sample rate:";
			this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
			// 
			// cbxSampleRate
			// 
			this.cbxSampleRate.Items.AddRange(new object[] {
															   "8000",
															   "16000",
															   "32000",
															   "44100",
															   "48000"});
			this.cbxSampleRate.Location = new System.Drawing.Point(80, 76);
			this.cbxSampleRate.Name = "cbxSampleRate";
			this.cbxSampleRate.Size = new System.Drawing.Size(64, 21);
			this.cbxSampleRate.TabIndex = 0;
			// 
			// btnSave
			// 
			this.btnSave.Location = new System.Drawing.Point(332, 348);
			this.btnSave.Name = "btnSave";
			this.btnSave.Size = new System.Drawing.Size(64, 24);
			this.btnSave.TabIndex = 1;
			this.btnSave.Text = "Save";
			this.btnSave.Click += new System.EventHandler(this.btnSave_Click);
			// 
			// btnCancel
			// 
			this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
			this.btnCancel.Location = new System.Drawing.Point(260, 348);
			this.btnCancel.Name = "btnCancel";
			this.btnCancel.Size = new System.Drawing.Size(64, 24);
			this.btnCancel.TabIndex = 1;
			this.btnCancel.Text = "Cancel";
			// 
			// grpQuality
			// 
			this.grpQuality.Controls.Add(this.lblMaxTrack);
			this.grpQuality.Controls.Add(this.lblMinTrack);
			this.grpQuality.Controls.Add(this.txtQuality);
			this.grpQuality.Controls.Add(this.trackBarQuality);
			this.grpQuality.Location = new System.Drawing.Point(4, 272);
			this.grpQuality.Name = "grpQuality";
			this.grpQuality.Size = new System.Drawing.Size(392, 68);
			this.grpQuality.TabIndex = 3;
			this.grpQuality.TabStop = false;
			this.grpQuality.Text = "Quality (bitrate)";
			// 
			// lblMaxTrack
			// 
			this.lblMaxTrack.Location = new System.Drawing.Point(344, 48);
			this.lblMaxTrack.Name = "lblMaxTrack";
			this.lblMaxTrack.Size = new System.Drawing.Size(32, 12);
			this.lblMaxTrack.TabIndex = 3;
			this.lblMaxTrack.Text = "10";
			this.lblMaxTrack.TextAlign = System.Drawing.ContentAlignment.TopRight;
			// 
			// lblMinTrack
			// 
			this.lblMinTrack.Location = new System.Drawing.Point(84, 48);
			this.lblMinTrack.Name = "lblMinTrack";
			this.lblMinTrack.Size = new System.Drawing.Size(20, 12);
			this.lblMinTrack.TabIndex = 2;
			this.lblMinTrack.Text = "-1";
			// 
			// txtQuality
			// 
			this.txtQuality.Location = new System.Drawing.Point(28, 32);
			this.txtQuality.Name = "txtQuality";
			this.txtQuality.Size = new System.Drawing.Size(40, 20);
			this.txtQuality.TabIndex = 1;
			this.txtQuality.Text = "";
			// 
			// trackBarQuality
			// 
			this.trackBarQuality.Location = new System.Drawing.Point(80, 16);
			this.trackBarQuality.Maximum = 100;
			this.trackBarQuality.Minimum = -10;
			this.trackBarQuality.Name = "trackBarQuality";
			this.trackBarQuality.Size = new System.Drawing.Size(304, 45);
			this.trackBarQuality.TabIndex = 0;
			this.trackBarQuality.TickFrequency = 10;
			this.trackBarQuality.ValueChanged += new System.EventHandler(this.trackBarQuality_ValueChanged);
			// 
			// btnOggVorbis
			// 
			this.btnOggVorbis.Location = new System.Drawing.Point(76, 20);
			this.btnOggVorbis.Name = "btnOggVorbis";
			this.btnOggVorbis.Size = new System.Drawing.Size(80, 16);
			this.btnOggVorbis.TabIndex = 5;
			this.btnOggVorbis.Text = "Ogg Vorbis";
			this.btnOggVorbis.Click += new System.EventHandler(this.btnOggVorbis_Click);
			// 
			// btnSpeex
			// 
			this.btnSpeex.Location = new System.Drawing.Point(172, 20);
			this.btnSpeex.Name = "btnSpeex";
			this.btnSpeex.Size = new System.Drawing.Size(56, 16);
			this.btnSpeex.TabIndex = 6;
			this.btnSpeex.Text = "Speex";
			this.btnSpeex.Click += new System.EventHandler(this.btnSpeex_Click);
			// 
			// btnMp3
			// 
			this.btnMp3.Location = new System.Drawing.Point(12, 20);
			this.btnMp3.Name = "btnMp3";
			this.btnMp3.Size = new System.Drawing.Size(48, 16);
			this.btnMp3.TabIndex = 7;
			this.btnMp3.Text = "MP3";
			this.btnMp3.Click += new System.EventHandler(this.btnMp3_Click);
			// 
			// groupBox2
			// 
			this.groupBox2.Controls.Add(this.label6);
			this.groupBox2.Controls.Add(this.txtCmdLineEncoder);
			this.groupBox2.Controls.Add(this.btnCustomEncoder);
			this.groupBox2.Controls.Add(this.btnOggVorbis);
			this.groupBox2.Controls.Add(this.btnSpeex);
			this.groupBox2.Controls.Add(this.btnMp3);
			this.groupBox2.Location = new System.Drawing.Point(8, 176);
			this.groupBox2.Name = "groupBox2";
			this.groupBox2.Size = new System.Drawing.Size(392, 88);
			this.groupBox2.TabIndex = 8;
			this.groupBox2.TabStop = false;
			this.groupBox2.Text = "Encoding";
			// 
			// label6
			// 
			this.label6.Location = new System.Drawing.Point(12, 68);
			this.label6.Name = "label6";
			this.label6.Size = new System.Drawing.Size(376, 16);
			this.label6.TabIndex = 10;
			this.label6.Text = "Note: %f will be replaced with file naming rules using destination directory.";
			// 
			// txtCmdLineEncoder
			// 
			this.txtCmdLineEncoder.Location = new System.Drawing.Point(8, 40);
			this.txtCmdLineEncoder.Name = "txtCmdLineEncoder";
			this.txtCmdLineEncoder.Size = new System.Drawing.Size(376, 20);
			this.txtCmdLineEncoder.TabIndex = 9;
			this.txtCmdLineEncoder.Text = "apeenc - -r -B 16 -C 2 -R 44100 -o \"%f.ape\"";
			// 
			// btnCustomEncoder
			// 
			this.btnCustomEncoder.Location = new System.Drawing.Point(244, 20);
			this.btnCustomEncoder.Name = "btnCustomEncoder";
			this.btnCustomEncoder.Size = new System.Drawing.Size(136, 16);
			this.btnCustomEncoder.TabIndex = 8;
			this.btnCustomEncoder.Text = "Custom Commandline";
			this.btnCustomEncoder.Click += new System.EventHandler(this.btnCustomEncoder_Click);
			// 
			// FrmConfig
			// 
			this.AcceptButton = this.btnSave;
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.CancelButton = this.btnCancel;
			this.ClientSize = new System.Drawing.Size(406, 380);
			this.Controls.Add(this.groupBox2);
			this.Controls.Add(this.grpQuality);
			this.Controls.Add(this.btnSave);
			this.Controls.Add(this.groupBox1);
			this.Controls.Add(this.btnCancel);
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
			this.MaximizeBox = false;
			this.MinimizeBox = false;
			this.Name = "FrmConfig";
			this.ShowInTaskbar = false;
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
			this.Text = "Configuration";
			this.Load += new System.EventHandler(this.FrmConfig_Load);
			this.groupBox1.ResumeLayout(false);
			((System.ComponentModel.ISupportInitialize)(this.sliderTime)).EndInit();
			this.grpQuality.ResumeLayout(false);
			((System.ComponentModel.ISupportInitialize)(this.trackBarQuality)).EndInit();
			this.groupBox2.ResumeLayout(false);
			this.ResumeLayout(false);
		}
		#endregion

		private void btnDirectoryBrowse_Click(object sender, System.EventArgs e)
		{
			FolderBrowserDialog fbd = new FolderBrowserDialog();
			fbd.SelectedPath = txtDirectoryPath.Text;
			if (fbd.ShowDialog() == DialogResult.OK)
			{
				txtDirectoryPath.Text = fbd.SelectedPath;
			}
		}

		private void FrmConfig_Load(object sender, System.EventArgs e)
		{
			cbxSampleRate.SelectedItem = AppConfigure.GetAppSetting("SampleRate");
			cbxBitsPerSample.SelectedItem = AppConfigure.GetAppSetting("BitsPerSample");
			cbxNumOfChannels.SelectedItem = AppConfigure.GetAppSetting("NumberOfChannels");

			txtFilenameMask.Text = AppConfigure.GetAppSetting("FilenameMask");
			txtDirectoryPath.Text = AppConfigure.GetAppSetting("DestinationDirectory");

			// double value so put in 2.01 hours so the rounding works good.
			sliderTime.Maximum = DateTime.Now + TimeSpan.FromHours(2.01);
			sliderTime.Minimum = DateTime.Now;

			DateTime time = sliderTime.Minimum + TimeSpan.Parse(AppConfigure.GetAppSetting("MaxRecordingTime", "00:00"));
			sliderTime.Value = time;

			selectedEncoder = AppConfigure.GetAppSetting("SelectedEncoder");

			qualityLameEncoding = AppConfigure.GetAppSetting("lameQuality");
			qualityOggVorbisEncoding = AppConfigure.GetAppSetting("oggencQuality");
			qualitySpeexEncoding = AppConfigure.GetAppSetting("speexencQuality");

			txtCmdLineEncoder.Text = AppConfigure.GetAppSetting("CustomEncoder");

			ConfigureRadioButtons();
		}

		private void btnSave_Click(object sender, System.EventArgs e)
		{
			AppConfigure.SetAppSetting("SampleRate", cbxSampleRate.SelectedItem.ToString());
			AppConfigure.SetAppSetting("BitsPerSample", cbxBitsPerSample.SelectedItem.ToString());
			AppConfigure.SetAppSetting("NumberOfChannels", cbxNumOfChannels.SelectedItem.ToString());

			AppConfigure.SetAppSetting("FilenameMask", txtFilenameMask.Text);
			AppConfigure.SetAppSetting("DestinationDirectory", txtDirectoryPath.Text);

			AppConfigure.SetAppSetting("MaxRecordingTime", sliderTime.ToString());

			AppConfigure.SetAppSetting("SelectedEncoder", selectedEncoder);

			AppConfigure.SetAppSetting("lameQuality", qualityLameEncoding);
			AppConfigure.SetAppSetting("oggencQuality", qualityOggVorbisEncoding);
			AppConfigure.SetAppSetting("speexencQuality", qualitySpeexEncoding);

			AppConfigure.SetAppSetting("CustomEncoder", txtCmdLineEncoder.Text);


			DialogResult = DialogResult.OK;
			Close();
		}

		private void trackBarQuality_ValueChanged(object sender, System.EventArgs e)
		{
			txtQuality.Text = (trackBarQuality.Value / trackBarDivider).ToString();

			switch (selectedEncoder)
			{
				case EncoderDefs.Lame :
				{
					qualityLameEncoding = txtQuality.Text;
					break;
				}
				case EncoderDefs.OggVorbis :
				{
					qualityOggVorbisEncoding = txtQuality.Text;
					break;
				}
				case EncoderDefs.Speex :
				{
					qualitySpeexEncoding = txtQuality.Text;
					break;
				}
			}
		}

		private void btnMp3_Click(object sender, System.EventArgs e)
		{
			selectedEncoder = EncoderDefs.Lame;
			ConfigureRadioButtons();		
		}

		private void btnOggVorbis_Click(object sender, System.EventArgs e)
		{
			selectedEncoder = EncoderDefs.OggVorbis;
			ConfigureRadioButtons();		
		}

		private void btnSpeex_Click(object sender, System.EventArgs e)
		{
			selectedEncoder = EncoderDefs.Speex;
			ConfigureRadioButtons();		
		}

		private void btnCustomEncoder_Click(object sender, System.EventArgs e)
		{
			selectedEncoder = EncoderDefs.CustomEncoder;
			ConfigureRadioButtons();		
		}

		private void ConfigureRadioButtons()
		{
			switch (selectedEncoder)
			{
				case EncoderDefs.Lame :
				{
					btnMp3.Select();

					trackBarQuality.Minimum = 8;
					trackBarQuality.Maximum = 320;
					trackBarQuality.TickFrequency = 8;
					trackBarQuality.SmallChange = 8;

					trackBarDivider = 1.0;

					lblMinTrack.Text = "8";
					lblMaxTrack.Text = "320";

					//					txtQuality.Text = qualityLameEncoding;
					trackBarQuality.Value = (int)(System.Convert.ToDouble(qualityLameEncoding) * trackBarDivider);

					grpQuality.Enabled = true;
					txtCmdLineEncoder.Enabled = false;	
					break;
				}
				case EncoderDefs.OggVorbis :
				{
					btnOggVorbis.Select();

					trackBarQuality.Minimum = -10;
					trackBarQuality.Maximum = 100;
					trackBarQuality.TickFrequency = 10;
					trackBarQuality.SmallChange = 1;

					trackBarDivider = 10.0;

					lblMinTrack.Text = "-1";
					lblMaxTrack.Text = "10";

					trackBarQuality.Value = (int)(System.Convert.ToDouble(qualityOggVorbisEncoding) * trackBarDivider);

					grpQuality.Enabled = true;
					txtCmdLineEncoder.Enabled = false;

					break;
				}
				case EncoderDefs.Speex :
				{
					btnSpeex.Select();

					trackBarQuality.Minimum = 0;
					trackBarQuality.Maximum = 100;
					trackBarQuality.TickFrequency = 10;
					trackBarQuality.SmallChange = 1;

					trackBarDivider = 10.0;

					lblMinTrack.Text = "0";
					lblMaxTrack.Text = "10";

					trackBarQuality.Value = (int)(System.Convert.ToDouble(qualitySpeexEncoding) * trackBarDivider);

					grpQuality.Enabled = true;
					txtCmdLineEncoder.Enabled = false;

					break;
				}
				case EncoderDefs.CustomEncoder :
				{
					btnCustomEncoder.Select();

					grpQuality.Enabled = false;
					txtCmdLineEncoder.Enabled = true;

					break;
				}	

			}
		}
	}
}
